﻿//alert("hi!");

function TGToggleR(tableid, basepart, id, endpart) {
	var tbl = document.getElementById(tableid).children[0];
	var src = '' + basepart + id + endpart;
	var advsrc = new Object();

	var mdv = 'b';

	var ri = document.getElementById(src + 'img');

	if (ri == null) return;

	if (ri.src.indexOf('_layouts/images/minus.gif', 0) >= 0) {
		mdv = 'h';

		ri.src = '_layouts/images/plus.gif';
		ri.alt = 'Развернуть';
	} else if (ri.src.indexOf('_layouts/images/plus.gif', 0) >= 0) {
		mdv = 's';

		ri.src = '_layouts/images/minus.gif';
		ri.alt = 'Свернуть';
	}

	if (mdv == 'b') return;

	for (var I = 0; I < tbl.children.length; I++) {
		var r = tbl.children[I];

		var rid = '' + r.id;
		var li = rid.lastIndexOf('_');

		if (li < 0) continue;

		var ridm = rid.substr(0, li + 1);
		var rids = '' + basepart + rid.substr(li + 1) + endpart;

		if (ridm == src || advsrc[ridm] == mdv) {
			if (mdv == 'h') {
				r.style.display = 'none';

				advsrc[rids] = 'h';
			} else if (mdv == 's') {
				r.style.display = '';

				var ris = document.getElementById(rids + 'img');

				if (ris != null && ris.src.indexOf('_layouts/images/minus.gif', 0) >= 0)
					advsrc[rids] = 's';
			}
		}
	}
}

function ShowFloatTitle(idp, idc) {
	var P = hGetObject(idp);
	var C = hGetObject(idc);

	if (P == null || C == null) return;

	C.style.top = hGetY(P) + 10;
	C.style.left = hGetX(P) + 50;

	C.style.display = 'block';
}

function HideFloatTitle(idc) {
	var C = hGetObject(idc);

	if (C == null) return;

	C.style.display = 'none';
}

var T_MAXLEN = 64;
var T_MAXLEN_WORD = 7;

var VCattable = new Array("по ", "ул.", "от ", "до ", "сет", "микрорайон", "м-н", "мкр", "работ", "улиц", "модул", "орган", "детски", "школ", "берегоукреплен", "благоустройств", "магистральны", "внутриплощадочн", "внеплощадочн", "водопровод", "бульвар", "мост", "рек", "канализаци", "дождев", "электроснабжен", "наружн", "инженерн", "здани", "теплоснабжени", "кабеле", "коллектор", "театр", "ливнево", "самотечны", "проектировани", "строительств", "реконструкци", "трубопровод", "водовод", "центральны", "зонировани", "комплекс", "жилой дом", "жило", "перепланиров", "част", "помещени", "застройк", "водозабор", "переход", "групп", "местно", "самоуправлени", "музыкальна", "лице", "поликлиник", "станци", "памятнико", "библиотек", "выставочны", "выполнени", "строительно-монтажны", "объект", "оборудовани", "проектн", "инфраструктур", "капитально", "строительств", "образовани", "культур", "\"", "«", "»", "'", "пуско-наладочн");
var VReplace = new Array(null, null, null, null, null, "м-н", null, null, "раб.", "ул.", "мод.", "орг.", "дет", "шк", "б/укр", "б/устр", "магистр.", "вну/пл", "вне/пл", "водопр.", "б.", "м.", "р.", "канализ.", "дожд.", "эл/снаб", "наруж.", "инж.", "зд", "теп/снаб", "каб.", "колл.", "т.", "ливн.", "самотеч.", "прект.", "стр.", "реконстр.", "тр/пров", "водов.", "центр.", "зонир.", "компл.", "ж/д", "жил.", "перепл.", null, "помещ.", "застр.", "водоз.", null, "гр.", "мест.", "самоупр.", "муз.", "лиц.", "поликл.", "ст.", "пам.", "библ.", "выстав.", "вып.", "СМР", "об.", "оборуд.", "проект.", "инфр.", "кап.", "стр.", "обр.", "культ.", "тоже, но БЕЗ кавычек", "тоже, но БЕЗ кавычек", "тоже, но БЕЗ кавычек", "тоже, но БЕЗ кавычек", "ПНР");

function SSP_CheckTitle(value, fieldname) {
	if (value == null || value.length <= 0) {
		alert("Внимание! Поле " + fieldname + " обязательно для заполнения!");
		return;
	}

	var MsgStr = "";
	var SAdded = false;
	var SM = (value.length <= T_MAXLEN);

	if (!SM) MsgStr = "Внимание! Поле " + fieldname + " слишком длинное! Его необходимо сократить до " + T_MAXLEN + " символов!";

	var Words = value.split(" ");

	if (Words == null) return;

	for (var w = 0; w < Words.length; w++) {
		var Word = Words[w];
		var NW = Word.toLocaleLowerCase() + " ";
		var VR = null;
		var VF = false;
		var LE = (Word.length > T_MAXLEN_WORD);

		if (SM && !LE) continue;

		for (var v = 0; v < VCattable.length; v++) {
			var VW = VCattable[v];

			//if (NW.length >= VW.length)
			//  alert("("+NW.substr(0, VW.length)+")("+NW.substr(NW.length-VW.length, VW.length)+")==("+VW+")");

			// Слово в списке?
			if ((NW.length >= VW.length) && (NW.substr(0, VW.length) == VW || NW.substr(NW.length - VW.length - 1, VW.length) == VW)) {
				VF = true;
				VR = VReplace[v];

				break;
			}
		}

		// Скажем об этом пользователю
		if (VF || LE) {
			if (!SAdded) {
				if (SM)
					MsgStr += "Желательно сократить в поле " + fieldname + " слова:\n";
				else
					MsgStr += "\n\nНеобходимо сократить в поле " + fieldname + " слова:\n";

				SAdded = true;
			}

			if (VR == null)
				MsgStr += "\n'" + Word + "' \t- сократить";
			else
				MsgStr += "\n'" + Word + "' \t- заменить на '" + VR + "'";
		}
	}

	if (MsgStr.length > 0)
		alert(MsgStr);
	else
		alert("Поле " + fieldname + " заполнено правильно!");
}

function SSP_CheckTitleEx(fieldName) {
	var theInput = getTagFromIdentifierAndTitle("input", "", fieldName);

	if (theInput != null)
		SSP_CheckTitle(theInput.value, fieldName);
}

function SSP_CheckTitle4Commit(fieldName) {
	var theInput = getTagFromIdentifierAndTitle("input", "", fieldName);

	if (theInput == null) return true;

	if (theInput.value == null || theInput.value.length <= 0) {
		alert("Поле " + fieldName + " должно быть заполнено!");
		return false;
	} else if (theInput.value.length > T_MAXLEN) {
		alert("Поле " + fieldName + " должно быть короче " + T_MAXLEN + " символов!");
		return false;
	}

	return true;
}

var T_OLDOCF_0 = null;
var T_OLDOCF_1 = null;
var T_OLDOCF_2 = null;
var T_OLDOCF_3 = null;
var T_C4C_FN = null;

function SSP_InjectCheck4Commit(buttonName, fieldName) {
	var tags = document.getElementsByTagName("input");
	var Cnt = 0;

	T_C4C_FN = fieldName;

	for (var i = 0; i < tags.length; i++) {
		var valueString = tags[i].value;

		if (tags[i].value == buttonName) {
			switch (Cnt) {
			case 0:
				T_OLDOCF_0 = tags[i].onclick;
				tags[i].onclick = iSSP_Check4Commit_0;
				break;
			case 1:
				T_OLDOCF_1 = tags[i].onclick;
				tags[i].onclick = iSSP_Check4Commit_1;
				break;
			case 2:
				T_OLDOCF_2 = tags[i].onclick;
				tags[i].onclick = iSSP_Check4Commit_2;
				break;
			case 3:
				T_OLDOCF_3 = tags[i].onclick;
				tags[i].onclick = iSSP_Check4Commit_3;
				break;
			}
		}
	}

	return true;
}

function iSSP_Check4Commit_0() {
	if (SSP_CheckTitle4Commit(T_C4C_FN))
		T_OLDOCF_0();
}

function iSSP_Check4Commit_1() {
	if (SSP_CheckTitle4Commit(T_C4C_FN))
		T_OLDOCF_1();
}

function iSSP_Check4Commit_2() {
	if (SSP_CheckTitle4Commit(T_C4C_FN))
		T_OLDOCF_2();
}

function iSSP_Check4Commit_3() {
	if (SSP_CheckTitle4Commit(T_C4C_FN))
		T_OLDOCF_3();
}


function hDoCall(spanid, msg) {
	var spid = hGetObject(spanid);

	if (spid == null) return;

	__doPostBack(spid.innerText, msg);
}

function hDoFilter(spanid, filterfield, filterval, additional) {
	hDoCall(spanid, 'NotUTF8;dvt_filterfield={' + filterfield + '};dvt_filterval={' + filterval + '};' + additional);
}

function hDoSortString(spanid, sortfield, sortdir) {
	hDoCall(spanid, 'dvt_sortfield={' + sortfield + '};dvt_sortdir={' + sortdir + '};dvt_sorttype={x:string};');
}

function hDoSortFloat(spanid, sortfield, sortdir) {
	DoCall(spanid, 'dvt_sortfield={' + sortfield + '};dvt_sortdir={' + sortdir + '};dvt_sorttype={x:float};');
}

function hDoSortFloat(spanid, sortfield, sortdir) {
	DoCall(spanid, 'dvt_sortfield={' + sortfield + '};dvt_sortdir={' + sortdir + '};dvt_sorttype={x:dateTime};');
}

function hGetObject(id) {
	if (document.all)
		return document.all[id];

	return document.getElementById(id);
}

function hGetWidth(obj) {
	var width = obj.offsetWidth;

	if (width > 0 || !hIsTRNode(obj))
		return width;

	if (!obj.firstChild)
		return 0;

	return obj.lastChild.offsetLeft - obj.firstChild.offsetLeft + hGetWidth(obj.lastChild);
}

function hGetHeight(obj) {
	var height = obj.offsetHeight;

	if (height > 0 || !hIsTRNode(obj))
		return height;

	if (!obj.firstChild)
		return 0;

	return obj.firstChild.offsetHeight;
}

function hGetX(obj) {
	var x = 0;

	do {
		x += obj.offsetLeft;
		obj = obj.offsetParent;
	} while (obj);

	return x;
}

function hGetXAt(obj, elm) {
	var x = 0;

	while (obj && obj != elm) {
		x += obj.offsetLeft;
		obj = obj.offsetParent;
	}

	if (obj == elm)
		return x;

	return x - hGetX(elm);
}

function hGetY(obj) {
	var y = 0;

	do {
		y += obj.offsetTop;
		obj = obj.offsetParent;
	} while (obj);

	return y;
}

function hIsTRNode(obj) {
	var tagName = obj.tagName;

	return tagName == "TR" || tagName == "tr" || tagName == "Tr" || tagName == "tR";
}

function hGetYAt(obj, elm) {
	var y = 0;

	if (!obj.offsetHeight && hIsTRNode(obj)) {
		var firstTR = obj.parentNode.firstChild;
		obj = obj.firstChild;
		y -= firstTR.firstChild.offsetTop;
	}

	while (obj && obj != elm) {
		y += obj.offsetTop;
		obj = obj.offsetParent;
	}

	if (obj == elm)
		return y;

	return y - hGetY(elm);
}

function setTextFromFieldName(fieldName, value, idcontains) {
	if (value == undefined) return;

	var theInput = getTagFromIdentifierAndTitle("input", "", fieldName, "", idcontains);

	if (theInput != null)
		theInput.value = value;
}

function setHideTextFromFieldName(fieldName, value) {
	var control = getTagFromIdentifierAndTitle("input", "", fieldName);

	if (control == null) return;

	var trcontrol = FindParentByTag(control, "tr");

	if (trcontrol == null) return;

	if (value == "hide")
		trcontrol.style.display = "none";
	else
		trcontrol.style.display = "";
}

function setPeopleFromFieldName(fieldName, value) {
	if (value == undefined) return;

	// NOT GOOD VARIANT!!!
	// It founds but it can determine what it founds

	var assignedToInput = getTagFromIdentifierAndTitle("div", "", "Выбор людей");

	if (assignedToInput != null)
		assignedToInput.innerHTML = value;
}

function setHidePeopleFromFieldName(fieldName, value) {
	var control = getTagFromIdentifierAndTitle("div", "", "Выбор людей");

	if (control == null) return;

	var trcontrol = FindParentByTag(control, "tr");

	if (trcontrol == null) return;

	if (value == "hide")
		trcontrol.style.display = "none";
	else
		trcontrol.style.display = "";
}

function setYesNoFromFieldName(fieldName, value) {
	var theInput = getTagFromIdentifierAndTitle("input", "BooleanField", fieldName);

	if (value == "true") {
		theInput.checked = "True";
	} else {
		theInput.checked = "False";
	}
}

function setHideYesNoFromFieldName(fieldName, value) {
	var control = getTagFromIdentifierAndTitle("input", "BooleanField", fieldName);

	if (control == null) return;

	var trcontrol = FindParentByTag(control, "tr");

	if (trcontrol == null) return;

	if (value == "hide")
		trcontrol.style.display = "none";
	else
		trcontrol.style.display = "";
}

function setHideLookupFromFieldName(fieldName, value) {
	var control = getTagFromIdentifierAndTitle("select", "Lookup", fieldName);

	// if control is null, it means that the target list has more than
	// 20 items, and the Lookup is being rendered with an input element

	if (control == null)
		control = getTagFromIdentifierAndTitle("input", "", fieldName);

	if (control == null) return;

	var trcontrol = FindParentByTag(control, "tr");

	if (trcontrol == null) return;

	if (value == "hide")
		trcontrol.style.display = "none";
	else
		trcontrol.style.display = "";
}

function setLookupFromFieldName(fieldName, value, idcontains) {
	if (value == undefined) return;

	//alert('setLookupFromFieldName='+value);

	var theSelect = getTagFromIdentifierAndTitle("select", "Lookup", fieldName, "", idcontains);

	//alert("theSelect="+theSelect);

	// if theSelect is null, it means that the target list has more than
	// 20 items, and the Lookup is being rendered with an input element

	if (theSelect == null) {
		var theInput = getTagFromIdentifierAndTitle("input", "", fieldName, "", idcontains);

		//alert("theInput="+theInput);

		if (theInput == null) return;

		ShowDropdown(theInput.id); //this function is provided by SharePoint 

		var opt = document.getElementById(theInput.opt);

		setSelectedOption(opt, value);

		OptLoseFocus(opt); //this function is provided by SharePoint 
	} else {
		setSelectedOption(theSelect, value);
	}
}

function setSelectedOption(select, value) {
	var opts = select.options;
	var l = opts.length;

	//alert("V1: select=" + select);


	if (select == null) return false;

	//alert("V1: " + value);

	for (var i = 0; i < l; i++) {
		//alert('opts[i].value='+opts[i].value+'?'+value);
		if (opts[i].value == value) {
			select.selectedIndex = i;
			//alert('selected opts[i].value='+opts[i].value+'=='+value);
			return true;
		}
	}

	//alert("V2: " + value);

	for (var i = 0; i < l; i++) {
		if (opts[i].text == value) {
			select.selectedIndex = i;
			return true;
		}
	}

	return false;
}

function setHideChoiceFromFieldName(fieldName, value) {
	var control = getTagFromIdentifierAndTitle("select", "DropDownChoice", fieldName);

	if (control == null) return;

	var trcontrol = FindParentByTag(control, "tr");

	if (trcontrol == null) return;

	if (value == "hide")
		trcontrol.style.display = "none";
	else
		trcontrol.style.display = "";
}

function setChoiceFromFieldName(fieldName, value, idcontains) {
	if (value == undefined) return;

	var theSelect = getTagFromIdentifierAndTitle("select", "DropDownChoice", fieldName, "", idcontains);

	//alert("theSelect="+theSelect);

	setSelectedOption(theSelect, value);
}

//SharePoint Field Type identifier    tagName     Option
//--------------------- --------------  ----------  ---------
//Single Line of Text   TextField   input 
//Multiple Lines of Text  TextArea    input 
//Number          TextField   input 
//Currency        TextField   input 
//Choice (radio buttons)  RadioButtons  input
//Choice (radio buttons)  RadioButtons  input       value
//Choice (dropdown)   DropDownChoice  select 
//Lookup (single)*    Lookup      select 
//Lookup (multiple)   SelectCandidate;
//            SelectResult  select 
//Yes/No          BooleanField  input 
//

function getTagFromIdentifierAndTitle(tagName, identifier, title, option, idcontains) {
	var len = identifier.length;
	var tags = document.getElementsByTagName(tagName);

	if (option == null) option = "";
	if (idcontains == null) idcontains = "";

	for (var i = 0; i < tags.length; i++) {
		var idString = tags[i].id;
		var nameString = tags[i].name;
		// get selected radio button value only
		if (option == "value" && tags[i].type == "radio" && (identifier == "RadioButtons" && nameString.indexOf(identifier) == nameString.length - len)) {
			var tagParentHTML = tags[i].parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.innerHTML;
			if (tagParentHTML.indexOf('FieldName="' + title + '"') > -1) {
				var radioButtons = document.getElementsByName(nameString);
				var radioValue = "";
				for (var x = 0; x < radioButtons.length; x++) {
					if (radioButtons[x].checked) {
						radioValue = radioButtons[x].parentElement.title;
						break;
					}
				}
				var o = document.createElement("INPUT");
				o.type = "hidden";
				o.value = radioValue;
				return o;
			}
		}
		// get radio buttons group
		if (tags[i].type == "radio" && (identifier == "RadioButtons" && nameString.indexOf(identifier) == nameString.length - len)) {
			var tagParentHTML = tags[i].parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.innerHTML;
			if (tagParentHTML.indexOf('FieldName="' + title + '"') > -1) {
				return document.getElementsByName(nameString);
			}
		}
			// all other input or select type by VALUE
		else if (option == "value" && tags[i].value == title && (identifier == "" || idString.indexOf(identifier) == idString.length - len) && (idcontains == "" || idString.indexOf(idcontains) > -1)) {
			return tags[i];
		}
			// all other input or select type
		else if (tags[i].title == title && (identifier == "" || idString.indexOf(identifier) == idString.length - len) && (idcontains == "" || idString.indexOf(idcontains) > -1)) {
			return tags[i];
		}
	}

	return null;
}

function getTagsFromIdentifierAndTitle(tagName, identifier, title, option, idcontains) {
	var len = identifier.length;
	var tags = document.getElementsByTagName(tagName);
	var res = new Array();

	if (option == null) option = "";
	if (idcontains == null) idcontains = "";

	//alert("tags=" + tags.length);

	for (var i = 0; i < tags.length; i++) {
		var idString = tags[i].id;
		var nameString = tags[i].name;

		//alert("id=" + idString + ", name=" + nameString);

		// get selected radio button value only
		if (option == "value" && tags[i].type == "radio" && (identifier == "RadioButtons" && nameString.indexOf(identifier) == nameString.length - len)) {
			var tagParentHTML = tags[i].parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.innerHTML;
			if (tagParentHTML.indexOf('FieldName="' + title + '"') > -1) {
				var radioButtons = document.getElementsByName(nameString);
				var radioValue = "";
				for (var x = 0; x < radioButtons.length; x++) {
					if (radioButtons[x].checked) {
						radioValue = radioButtons[x].parentElement.title;
						break;
					}
				}
				var o = document.createElement("INPUT");
				o.type = "hidden";
				o.value = radioValue;
				return o;
			}
		}
		// get radio buttons group
		if (tags[i].type == "radio" && (identifier == "RadioButtons" && nameString.indexOf(identifier) == nameString.length - len)) {
			var tagParentHTML = tags[i].parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.innerHTML;
			if (tagParentHTML.indexOf('FieldName="' + title + '"') > -1) {
				res.push(document.getElementsByName(nameString));
			}
		}
			// all other input or select type by VALUE
		else if (option == "value" && tags[i].value == title && (identifier == "" || idString.indexOf(identifier) == idString.length - len) && (idcontains == "" || idString.indexOf(idcontains) > -1)) {
			res.push(tags[i]);
		}
			// all other input or select type
		else if (tags[i].title == title && (identifier == "" || idString.indexOf(identifier) == idString.length - len) && (idcontains == "" || idString.indexOf(idcontains) > -1)) {
			res.push(tags[i]);
		}
	}
	return res;
}

function getQSV(varName) {
	var arg = location.search.substring(1).split('&');
	var variable = "";

	for (var i = 0; i < arg.length; i++) {
		var splited = arg[i].split('=');

		//alert("splited[0]="+splited[0]+", varName="+varName+", splited[0] == varName: "+(splited[0] == varName));

		if (splited[0] == varName) {
			if (splited.length > 1) variable = splited[1];

			return variable;
		}
	}

	return "";
}


function removeQSV(href, Name) {
	// location.href
	var ohref = href;

	var iName = ohref.indexOf(Name);
	var lName = ohref.indexOf("&", iName);

	if (iName < 0) return ohref;

	var fphref = ohref.substr(0, iName);
	var sphref = "";
	var splen = ohref.length - lName - 1;

	if (lName > 0 && splen > 0)
		sphref = ohref.substr(lName + 1, splen);

	var nhref = ohref.substr(0, iName) + sphref;

	if (nhref.charAt(nhref.length - 1) == '?' || nhref.charAt(nhref.length - 1) == '&')
		nhref = nhref.substr(0, nhref.length - 1);

	return nhref;
}

function addQSV(href, Name, Value) {
	// location.href
	var ohref = href;

	if (ohref.indexOf('?') < 0)
		return ohref + "?" + Name + "=" + Value;
	else
		return ohref + "&" + Name + "=" + Value;
}


function setParentSize(divid, mfid, setwidth, setheight) {
	var pW = window.parent;

	if (pW == null) return;

	var divctrl = pW.document.all(divid);

	if (divctrl == null) return;

	var mfctrl = document.all(mfid);

	var dbctrl = document.body;

	if (mfctrl == null) mfctrl = dbctrl;

	//alert("body.sw="+document.body.scrollWidth+", .sh="+document.body.scrollHeight+",\n"+
	//      "mfid.sw="+document.all(mfid).scrollWidth+", .sh="+document.all(mfid).scrollHeight);

	if (setwidth)
		divctrl.style.width = (mfctrl.scrollWidth + 16) + "px";

	if (setheight)
		divctrl.style.height = (dbctrl.scrollHeight + 16) + "px";
}

function ConfirmRemove() {
	return confirm('Вы действительно хотите удалить?');
}

var ggD = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');

function GuidGenPart(len) {
	var res = '';

	for (var I = 0; I < len; I++) {
		res += ggD[Math.floor(Math.random() * 16)]; // значения будут идти от 0 и до 15
	}

	//alert('part len=' + len + ':' + res);

	return res;
}

function GuidGen() {
	// guid looks like d2a6a4d1-bcd8-5ca9-2cfa-8a143379ffff
	//alert("GuidGen");
	return GuidGenPart(8) + '-' + GuidGenPart(4) + '-' + GuidGenPart(4) + '-' + GuidGenPart(4) + '-' + GuidGenPart(12);
}

function FindParentByTag(Ctrl, TagName) {
	var Current = Ctrl;
	var tnlo = TagName.toLocaleLowerCase();

	while (Current != null && Current.tagName.toLocaleLowerCase() != tnlo) {
		Current = Current.parentElement;
	}

	return Current;
}

function FindChildrenByTag(Ctrl, TagName) {
	var tnlo = TagName.toLocaleLowerCase();

	for (var i = 0; i < Ctrl.childNodes.length; i++) {
		var Current = Ctrl.childNodes[i];

		if (Current.tagName.toLocaleLowerCase() == tnlo)
			return Current;
	}

	return null;
}

function CallParent(code) {
	var parent = window.parent;

	if (parent == null) return;

	parent.execScript(code);
}

function hFillComboBoxBy(cbCtrlID, Source, Key, KeyIdx, TitleIdx, ValueIdx) {
	var cbctrl = hGetObject(cbCtrlID);

	if (cbctrl == null) return;

	// empty the list
	if (cbctrl.options != null) {
		for (i in cbctrl.options.length) {
			cbctrl.options[i] = null;
		}
	}

	i = 0;

	for (x in Source) {
		if (Source[x][KeyIdx] == Key) {
			opt = new Option();

			opt.value = Source[x][ValueIdx];
			opt.text = Source[x][TitleIdx];

			if (i == 0) opt.selected = true;

			cbctrl.options[i++] = opt;
		}
	}

	cbctrl.length = i;
}

/*
function hShowHideTabDiv(showdivid, currentdivspanid) {
var sdiv = hGetObject(showdivid);
var span = hGetObject(currentdivspanid);

if (sdiv == null || span == null) return;
	
// Получаем отображаемый сейчас элемент
var visibledivid = span.innerText;

// Скрываем его
if (visibledivid != null && visibledivid != '') {
var vdiv = hGetObject(visibledivid);
var vdivtab = hGetObject("tab_" + visibledivid);

if (vdiv != null)
vdiv.style.display = 'none';

if (vdivtab != null)
vdivtab.className = 'card_tab_normal';
}

var sdivtab = hGetObject("tab_" + showdivid);

if (sdivtab != null)
sdivtab.className = 'card_tab_active';

// Показываем нужный элемент
sdiv.style.display = '';
span.innerText = showdivid;
}
*/

function GetWindowWidth() {
	var theWidth = window.screen.width;

	// Window dimensions: 
	if (window.innerWidth) {
		theWidth = window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		theWidth = document.documentElement.clientWidth;
	} else if (document.body) {
		theWidth = document.body.clientWidth;
	}
	return theWidth;
}

function GetWindowHeight() {
	var theHeight = window.screen.height;

	// Window dimensions: 
	if (window.innerHeight) {
		theHeight = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		theHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		theHeight = document.body.clientHeight;
	}
	return theHeight;
}